import {
	list,
	tag
} from '../../../api/article';
const util = require('../../../utils/util.js')
let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
	swiperHeight: 0,
	swiperList: [],
	tagIds: '',
	id: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  this.initSwiperHeightHeight()
	  this.initQuestion()
  },
  
  initSwiperHeightHeight() {
  	// 先取出页面高度 windowHeight
  	let windowHeight
  	wx.getSystemInfo({
  		success: (res) => {
  			windowHeight = res.windowHeight
  		}
  	})
  	let query = wx.createSelectorQuery().in(this)
  	// 逐个取出header和button的节点信息
  	query.select('.header').boundingClientRect()
  	query.select('.button').boundingClientRect()
  	// 执行上面所指定的请求，结果会按照顺序存放于一个数组中，在callback的第一个参数中返回
  	query.exec((res) => {
		console.log(res, 'rrrrrrrrrr')
  		let headerHeight = res[0].height
  		let buttonHeight = res[1].height
		console.log(windowHeight, headerHeight, buttonHeight)
  		let swiperHeight = windowHeight - headerHeight - buttonHeight
  		this.setData({ swiperHeight })
  	})
  },
  
  initQuestion () {
    let params = {
      'mchId': app.globalData.mchId,
      'type': 0,
    }
    tag(params).then(res => {
      console.log(res)
      res.data.data.forEach(item => {
        if (item.name === '新手指引') {
          this.data.tagIds = item.id
          // 查找新手指引
          list({'mchId': app.globalData.mchId, 'tagIds': this.data.tagIds}).then(res => {
  		  const swiperList = res.data.data
		  const id = res.data.data[0].id
  		  this.setData({ swiperList, id })
          }).catch(err => {
            console.log(err)
          })
        }
      })
    }).catch(err => {
      console.log(err)
    })
  },
  
  switchId(e) {
	const { swiperList } = this.data
	const id = swiperList[e.detail.current].id
	this.setData({ id })
  },
  
  detailClick () {
    wx.navigateTo({
    	url:`/pages/member/detail/detail?id=${this.data.id}`,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})